import os



'''
移除图片不存在的标注
删除均压环(jyh issue)所有图片
'''


base_dir = 'd:/image_augmentation/'
image_dir = base_dir + 'images/'
image_remove_dir = base_dir + 'images_remove/'
annotation_remove_dir = base_dir + 'annotations_remove/'
annotation_dir = base_dir + 'annotations/'


for p_dir,dirs,files in os.walk(annotation_dir):
    for name in files:
        id = os.path.splitext(name)[0]
        xml_path = annotation_dir + name;
        img_path = image_dir + id + '.jpg'
        if not os.path.exists(img_path) and os.path.exists(xml_path):
            os.rename(xml_path,annotation_remove_dir + name)

        if os.path.exists(xml_path):
            f = open(xml_path)
            content = f.read()
            if content.find('jyh') > -1:
                print(name)
                if os.path.exists(img_path):
                    os.rename(img_path,image_remove_dir+id+'.jpg')
